cmake_minimum_required(VERSION 3.16)
project(FigoPlayer VERSION 1.0.0 LANGUAGES CXX)

# 设置C++标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 设置编译选项
if(MSVC)
    add_compile_options(/W4)
else()
    add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# 查找FFmpeg
find_package(PkgConfig REQUIRED)
pkg_check_modules(FFMPEG REQUIRED
    libavcodec
    libavformat
    libavutil
    libswscale
    libswresample
)

# 查找Qt6 (可选)
find_package(Qt6 QUIET COMPONENTS Core Widgets)

# 包含目录
include_directories(${CMAKE_SOURCE_DIR}/src)
include_directories(${FFMPEG_INCLUDE_DIRS})

# 源文件
set(SOURCES
    src/main.cpp
    src/core/player_engine.cpp
    src/core/audio_decoder.cpp
    src/core/video_decoder.cpp
    src/core/audio_output.cpp
    src/core/video_output.cpp
    src/ui/main_window.cpp
    src/ui/player_widget.cpp
    src/utils/file_utils.cpp
    src/utils/logger.cpp
)

# 头文件
set(HEADERS
    src/core/player_engine.h
    src/core/audio_decoder.h
    src/core/video_decoder.h
    src/core/audio_output.h
    src/core/video_output.h
    src/ui/main_window.h
    src/ui/player_widget.h
    src/utils/file_utils.h
    src/utils/logger.h
)

# 创建可执行文件
add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})

# 链接库
target_link_libraries(${PROJECT_NAME} ${FFMPEG_LIBRARIES})

# 如果找到Qt6，链接Qt库
if(Qt6_FOUND)
    target_link_libraries(${PROJECT_NAME} Qt6::Core Qt6::Widgets)
    target_compile_definitions(${PROJECT_NAME} PRIVATE USE_QT6)
endif()

# 设置输出目录
set_target_properties(${PROJECT_NAME} PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)

# 安装规则
install(TARGETS ${PROJECT_NAME}
    RUNTIME DESTINATION bin
)
